<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>JSP 自定义标签 - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-04-25 11:26">
      April 25, 2019 am
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.1k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      47
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="JSP-自定义标签"><a href="#JSP-自定义标签" class="headerlink" title="JSP 自定义标签"></a>JSP 自定义标签</h2><h3 id="入门"><a href="#入门" class="headerlink" title="入门"></a>入门</h3><ol>
<li>什么是<code>JSP</code>自定义标签?</li>
</ol>
<p><em>自定义标签可以有效地将HTML代码与Java代码分类,从而使不懂Java编程的HTLML设计人员也可以编写出功能强大的JSP页面.JSP复规范中定义了多个用于开发自定义标签的接口和类,它们都位于<code>javax.servlet.jsp.tagext</code>包中,这些接口和类的继承关系如下所示.</em></p>
<p><img src="/2019/04/25/JSP-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A0%87%E7%AD%BE/java-servlet-jsp-tagext.png" srcset="/img/loading.gif" alt=" "></p>
<ol start="2">
<li>标签分类</li>
</ol>
<p><em>在<code>JSP2.0</code>之前,所有的标签都需要实现<code>Tag</code>接口,这样的标签称为: <code>传统标签( javax.servlet.jsp.tagext.Tag )</code>. 后来为了简化标签的开发,JSP2.0规范又定义了一种新类型的标签,称为<code>简单标签( javax.servlet.jsp.tagext.SimpleTag )</code></em></p>
<h3 id="自定义标签的开发步骤"><a href="#自定义标签的开发步骤" class="headerlink" title="自定义标签的开发步骤"></a>自定义标签的开发步骤</h3><ol>
<li>编写标签处理器</li>
</ol>
<p><em><code>Tag</code>接口和<code>SimpleTag</code>接口定义了JSP页面与标签处理器类之间的通信规则.如果JSP引擎在编译JSP页面时遇到了自定义标签,<code>传统标签</code>将会调用标签处理器的<code>doStartTag()</code>方法,简单标签将会调用标签处理器类的<code>doTag()</code>方法.</em></p>
<ol start="2">
<li>编写标签库描述符文件</li>
</ol>
<p><em>要想让JSP引擎在遇到自定义标签时,能找到其所对应的标签处理器,还必须编写是一个标签描述符( <code>Tag Library Descriptor</code> )文件.简称: <code>TLD</code>文件.</em></p>
<ul>
<li><em>注意: 自定义标签的根标签(<code>&lt;taglib&gt;</code>)使用的是schema约束.其标签内容可以从 : <code>&lt;Tomcat安装目录&gt;\webapps\examples\WEB-INF\jsp2\jsp2-example-taglib.tld</code>中复制即可.</em> </li>
</ul>
<ol start="3">
<li>在JSP页面导入和使用自定义标签</li>
</ol>
<p><em>TLD文件编写完成后,就可以在JSP文件中使用自定义标签.在使用自定义标签之前,首先需要使用<code>taglib</code>指令来引入TLD文件.</em></p>
<h3 id="传统标签"><a href="#传统标签" class="headerlink" title="传统标签"></a>传统标签</h3><ol>
<li><code>Tag</code> 接口</li>
</ol>
<p><em>Tag接口定义了JSP页面与标签处理器之前的通信规则,当JSP容器将JSP页面翻译成Servlet源文件时,如果遇到JSP标签,会创建标签处理器类的实例对象.然后依次调用标签处理器的如下方法.</em></p>
<div class="hljs"><pre><code class="hljs java">setPageContext() ——&gt; setParent() ——&gt; doStartTag() ——&gt; doEndTag() ---&gt; release()</code></pre></div>

<ol start="2">
<li><code>IterationTag</code> 接口</li>
</ol>
<p><em>在自定义标签的开发过程中,其可以对标签体的内容进行重复处理.</em></p>
<ul>
<li><em><code>TagSupport</code>类实现了该接口,简化了程序的编写.</em></li>
</ul>
<ol start="3">
<li><code>BodyTag</code> 接口</li>
</ol>
<p><em>在实现自定义标签时,其可以根据需要对标签体的内容进行处理后再向浏览器输出.</em></p>
<h4 id="案例-实现一个传统自定义标签"><a href="#案例-实现一个传统自定义标签" class="headerlink" title="案例-实现一个传统自定义标签"></a>案例-实现一个<code>传统</code>自定义标签</h4><p><em>描述 : 开发一个显示IP地址的自定义标签</em></p>
<ol>
<li><p>编写完成标签功能的标签处理器类</p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.tag.handler;

<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.TagSupport;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: IpTag
 * <span class="hljs-doctag">@Description</span>: 传统标签处理器
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: Apr 25, 2019 4:06:28 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">IpTag</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">TagSupport</span> </span>&#123;

	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> serialVersionUID = -<span class="hljs-number">8446674958888389920L</span>;

	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">doStartTag</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> JspException </span>&#123;

		String IP = pageContext.getRequest().getRemoteAddr();
		<span class="hljs-keyword">try</span> &#123;
			pageContext.getOut().write(<span class="hljs-string">"访问用户的IP地址为 : "</span> + IP);
		&#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;
			e.printStackTrace();
		&#125;

		<span class="hljs-keyword">return</span> <span class="hljs-keyword">super</span>.doStartTag();
	&#125;
&#125;</code></pre></div>
</li>
<li><p>编写TLD文件</p>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">taglib</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee"</span>
	<span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"</span>
	<span class="hljs-attr">version</span>=<span class="hljs-string">"2.0"</span>&gt;</span>

	<span class="hljs-comment">&lt;!-- 标签库的版本号 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tlib-version</span>&gt;</span>1.0<span class="hljs-tag">&lt;/<span class="hljs-name">tlib-version</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- 标签库的名称 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">short-name</span>&gt;</span>TraditionalTag<span class="hljs-tag">&lt;/<span class="hljs-name">short-name</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- 标签库的URI --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">uri</span>&gt;</span>https://yubuntu0109.github.io<span class="hljs-tag">&lt;/<span class="hljs-name">uri</span>&gt;</span>

	<span class="hljs-comment">&lt;!-- 注册一个自定义的标签 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tag</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 指定自定义标签的注册名称 --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>ipTag<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 指定标签的标签处理器类 --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">tag-class</span>&gt;</span>pers.huangyuhui.tag.handler.IpTag<span class="hljs-tag">&lt;/<span class="hljs-name">tag-class</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 指定标签的类型 --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">body-content</span>&gt;</span>empty<span class="hljs-tag">&lt;/<span class="hljs-name">body-content</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">tag</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">taglib</span>&gt;</span></code></pre></div>
</li>
<li><p>编写JSP文件,并导入和使用自定义标签</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span>
    <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%--</span> 导入自定义的标签库描述符文件 <span class="hljs-attr">--</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%@taglib</span> <span class="hljs-attr">uri</span>=<span class="hljs-string">"https://yubuntu0109.github.io"</span> <span class="hljs-attr">prefix</span>=<span class="hljs-string">"yu"</span> %&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>测试自定义标签<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">yu:ipTag</span>/&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>

</li>
</ol>
<h3 id="简单标签"><a href="#简单标签" class="headerlink" title="简单标签"></a>简单标签</h3><ol>
<li><code>SimpleTag</code> 接口</li>
</ol>
<p><em>SimpleTag接口中的方法和传统标签中定义的签名有所区别,但是功能却基本一致,例如: 都实现了给<code>标签处理器</code>传递<code>pageContext</code>对象和父标签处理器对象的功能.而且<code>JSP容器</code>执行简单标签处理器的顺序也和执行传统标签处理器的顺序一致.简单标签处理器的执行流程如下所示:</em></p>
<div class="hljs"><pre><code class="hljs java">JSP容器实例化标签处理器类 ——&gt; setJspContext() ——&gt; setParent() ——&gt; 设置属性的setter方法 ——&gt; setJspBody() ——&gt; doTag()</code></pre></div>

<ol start="2">
<li><code>JspFragment</code> 类</li>
</ol>
<p><em>JSP容器在处理简单标签时,会把标签体内容用一个JspFragment对象表示,并调用标签处理器对象的setJspBody()方法将JspFragment对象传递给标签处理器对象,标签开发者可以根据需要调用JspFragment对象的方法来决定是否输出标签体,或者循环多次输出标签体等.其中JspFragment的<code>invoke(Write out)</code>方法是简单标签开发中最重要的一个方法,它用于控制如何执行标签体的内容.</em></p>
<ol start="3">
<li><code>SimpleTagSupport</code> 类</li>
</ol>
<p><em>该类实现了<code>SimpleTagSupport</code>接口,继而使得简单标签处理器的编写变得简化.</em></p>
<h4 id="案例-实现一个自定义简单标签"><a href="#案例-实现一个自定义简单标签" class="headerlink" title="案例-实现一个自定义简单标签"></a>案例-实现一个自定义简单标签</h4><p><em>描述 : 自定义简单标签,实现重复执行标签体的功能.</em></p>
<ol>
<li><p>编写标签处理器类</p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.tag.handler;

<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.JspFragment;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.SimpleTagSupport;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: SimpleIterate
 * <span class="hljs-doctag">@Description</span>: 简单标签处理器
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: Apr 24, 2019 4:52:19 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SimpleIterate</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">SimpleTagSupport</span> </span>&#123;

	<span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> num;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setNum</span><span class="hljs-params">(<span class="hljs-keyword">int</span> num)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.num = num;
	&#125;

	<span class="hljs-meta">@Override</span>
	<span class="hljs-comment">// 对标签进行逻辑处理</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doTag</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> JspException, IOException </span>&#123;
		<span class="hljs-comment">// 获取标签体</span>
		JspFragment jspFragment = <span class="hljs-keyword">this</span>.getJspBody();

		<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; num; i++) &#123;
			jspFragment.invoke(<span class="hljs-keyword">null</span>);
		&#125;
	&#125;
&#125;</code></pre></div>
</li>
<li><p><em>编写简单标签库描述符文件</em></p>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">taglib</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee"</span>
	<span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"</span>
	<span class="hljs-attr">version</span>=<span class="hljs-string">"2.0"</span>&gt;</span>

	<span class="hljs-comment">&lt;!-- 标签库的版本号 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tlib-version</span>&gt;</span>1.0<span class="hljs-tag">&lt;/<span class="hljs-name">tlib-version</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- 标签库的名称 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">short-name</span>&gt;</span>SimpleTag<span class="hljs-tag">&lt;/<span class="hljs-name">short-name</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- 标签库的URI --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">uri</span>&gt;</span>/SimpleTag<span class="hljs-tag">&lt;/<span class="hljs-name">uri</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 注册一个自定义的标签 --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tag</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>simpleIterate<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">tag-class</span>&gt;</span>pers.huangyuhui.tag.handler.SimpleIterate<span class="hljs-tag">&lt;/<span class="hljs-name">tag-class</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">body-content</span>&gt;</span>scriptless<span class="hljs-tag">&lt;/<span class="hljs-name">body-content</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 用于描述自定义标签的属性 --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">attribute</span>&gt;</span>
			<span class="hljs-comment">&lt;!-- 指定属性的名称 --&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>num<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
			<span class="hljs-comment">&lt;!-- 指定在JSP页面调用自定义标签时是否必须设置这个属性 --&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">required</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">required</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">attribute</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">tag</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">taglib</span>&gt;</span></code></pre></div>
</li>
<li><p>编写JSP文件,并导入和使用自定义标签</p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span>
    <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%@taglib</span> <span class="hljs-attr">uri</span>=<span class="hljs-string">"/SimpleTag"</span>  <span class="hljs-attr">prefix</span>=<span class="hljs-string">"yu"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>测试自定义标签<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">yu:simpleIterate</span> <span class="hljs-attr">num</span>=<span class="hljs-string">"5"</span>&gt;</span>
				Hello SimpleTag !<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">yu:simpleIterate</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>

</li>
</ol>
<h4 id="案例-模拟JSTL的-lt-c-choose-gt-lt-c-when-gt-lt-c-otherwise-gt-标签"><a href="#案例-模拟JSTL的-lt-c-choose-gt-lt-c-when-gt-lt-c-otherwise-gt-标签" class="headerlink" title="案例-模拟JSTL的&lt;c:choose&gt;,&lt;c:when&gt;,&lt;c:otherwise&gt;标签"></a>案例-模拟<code>JSTL</code>的&lt;c:choose&gt;,&lt;c:when&gt;,&lt;c:otherwise&gt;标签</h4><p><em>描述 : 通过模仿<code>JSTL</code>核心标签库中的&lt;c:choose&gt;,&lt;c:when test=””&gt;,&lt;c:otherwise&gt;标签,开发一套自己的标签 :  <code>&lt;yu:choose&gt;</code>,<code>&lt;yu:when test=&quot;&quot;&gt;</code>,<code>&lt;yu:otherwise&gt;</code></em></p>
<ol>
<li><p><em>编写标签<code>&lt;yu:choose&gt;</code>的标签处理器类 : ChooseTag.java</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.tag.handler.choose;

<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.SimpleTagSupport;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: ChooseTag
 * <span class="hljs-doctag">@Description</span>: 标签处理器
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: Apr 24, 2019 5:15:53 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ChooseTag</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">SimpleTagSupport</span> </span>&#123;

	<span class="hljs-comment">// 作为标识符用于控制&lt;yu:when&gt;和&lt;yu:otherwise&gt;的标签体是否执行</span>
	<span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> flag;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">isFlag</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-keyword">return</span> flag;
	&#125;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setFlag</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> flag)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.flag = flag;
	&#125;

	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doTag</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> JspException, IOException </span>&#123;
		<span class="hljs-keyword">this</span>.getJspBody().invoke(<span class="hljs-keyword">null</span>);
	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>编写标签<code>&lt;yu:when test=&quot;&quot;&gt;</code>的标签处理器类 : WhenTag.java</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.tag.handler.choose;

<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspTagException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.JspTag;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.SimpleTagSupport;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: WhenTag
 * <span class="hljs-doctag">@Description</span>: 标签处理器
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: Apr 24, 2019 5:19:01 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">WhenTag</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">SimpleTagSupport</span> </span>&#123;

	<span class="hljs-comment">// 用于接收标签中`test`属性传入的值</span>
	<span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> test;

	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setTest</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> test)</span> </span>&#123;
		<span class="hljs-keyword">this</span>.test = test;
	&#125;

	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doTag</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> JspException, IOException </span>&#123;

		<span class="hljs-comment">// 获得父类标签对象</span>
		JspTag tag = <span class="hljs-keyword">this</span>.getParent();

		<span class="hljs-comment">// 判断父标签是否为: ChooseTag</span>
		<span class="hljs-keyword">if</span> (!(tag <span class="hljs-keyword">instanceof</span> ChooseTag)) &#123;
			<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> JspTagException(<span class="hljs-string">"ERROR : OUT OF CHOOSE TAG"</span>);
		&#125;

		<span class="hljs-comment">// 将父类标签对象强转成`ChooseTag`类型</span>
		ChooseTag chooseTag = (ChooseTag) tag;

		<span class="hljs-comment">// 判断`WhenFlag`为true且父标签中的`flag`为false时执行该标签体</span>
		<span class="hljs-keyword">if</span> (test &amp;&amp; !(chooseTag.isFlag())) &#123;
			<span class="hljs-keyword">this</span>.getJspBody().invoke(<span class="hljs-keyword">null</span>);

			<span class="hljs-comment">// 执行完标签体后,将父标签中的`flag`置为true,防止其它嵌套标签体继续执行</span>
			chooseTag.setFlag(<span class="hljs-keyword">true</span>);
		&#125;
	&#125;
&#125;</code></pre></div>
</li>
<li><p><em>编写<code>&lt;yu:otherwise&gt;</code>的标签体处理器类 : OtherwiseTag.java</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">package</span> pers.huangyuhui.tag.handler.choose;

<span class="hljs-keyword">import</span> java.io.IOException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.JspTagException;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.JspTag;
<span class="hljs-keyword">import</span> javax.servlet.jsp.tagext.SimpleTagSupport;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@ClassName</span>: OtherwishTag
 * <span class="hljs-doctag">@Description</span>: 标签处理器
 * <span class="hljs-doctag">@author</span>: HuangYuhui
 * <span class="hljs-doctag">@date</span>: Apr 24, 2019 5:46:33 PM
 * 
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OtherwiseTag</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">SimpleTagSupport</span> </span>&#123;

	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doTag</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> JspException, IOException </span>&#123;

		<span class="hljs-comment">// 获得父标签对象</span>
		JspTag jspTag = <span class="hljs-keyword">this</span>.getParent();

		<span class="hljs-comment">// 判断父标签是否是: ChooseTag</span>
		<span class="hljs-keyword">if</span> (!(jspTag <span class="hljs-keyword">instanceof</span> ChooseTag)) &#123;
			<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> JspTagException(<span class="hljs-string">"ERROR : OUT OF CHOOSE TAG"</span>);
		&#125;

		<span class="hljs-comment">// 将父类标签对象强转成`ChooseTag`类型</span>
		ChooseTag chooseTag = (ChooseTag) jspTag;

		<span class="hljs-comment">// 判断父标签中的`flag`为false时,执行该标签体</span>
		<span class="hljs-keyword">if</span> (!chooseTag.isFlag()) &#123;
			<span class="hljs-keyword">this</span>.getJspBody().invoke(<span class="hljs-keyword">null</span>);

			<span class="hljs-comment">// 执行完标签体后,将父标签中的`flag`置为true,防止其它嵌套标签体继续执行</span>
			chooseTag.setFlag(<span class="hljs-keyword">true</span>);
		&#125;

	&#125;

&#125;</code></pre></div>
</li>
<li><p><em>编写<code>TLD</code>文件</em></p>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">taglib</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee"</span>
	<span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"</span>
	<span class="hljs-attr">version</span>=<span class="hljs-string">"2.0"</span>&gt;</span>

	<span class="hljs-tag">&lt;<span class="hljs-name">description</span>&gt;</span>模拟JSTL的choose,when,otherwish标签<span class="hljs-tag">&lt;/<span class="hljs-name">description</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tlib-version</span>&gt;</span>1.0<span class="hljs-tag">&lt;/<span class="hljs-name">tlib-version</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">short-name</span>&gt;</span>SimpleTag<span class="hljs-tag">&lt;/<span class="hljs-name">short-name</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">uri</span>&gt;</span>https://yubuntu0109.github.io<span class="hljs-tag">&lt;/<span class="hljs-name">uri</span>&gt;</span>

	<span class="hljs-comment">&lt;!-- choose tag --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tag</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>choose<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">tag-class</span>&gt;</span>pers.huangyuhui.tag.handler.choose.ChooseTag<span class="hljs-tag">&lt;/<span class="hljs-name">tag-class</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">body-content</span>&gt;</span>scriptless<span class="hljs-tag">&lt;/<span class="hljs-name">body-content</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">tag</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- when tag --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tag</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>when<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">tag-class</span>&gt;</span>pers.huangyuhui.tag.handler.choose.WhenTag<span class="hljs-tag">&lt;/<span class="hljs-name">tag-class</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">body-content</span>&gt;</span>scriptless<span class="hljs-tag">&lt;/<span class="hljs-name">body-content</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">attribute</span>&gt;</span>
			<span class="hljs-comment">&lt;!-- 
			注意: 属性名一定要和该标签的处理器类中的属性名一致 !
			否则抛出异常:  Unable to find setter method for attribute: xxx ..
			--&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">required</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">required</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">rtexprvalue</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">rtexprvalue</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">attribute</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">tag</span>&gt;</span>
	<span class="hljs-comment">&lt;!-- otherwise tag --&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">tag</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>otherwise<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">tag-class</span>&gt;</span>pers.huangyuhui.tag.handler.choose.OtherwiseTag<span class="hljs-tag">&lt;/<span class="hljs-name">tag-class</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">body-content</span>&gt;</span>scriptless<span class="hljs-tag">&lt;/<span class="hljs-name">body-content</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">tag</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">taglib</span>&gt;</span></code></pre></div>
</li>
<li><p><em>编写两个JSP文件,对三个自定义标签进行测试.</em></p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span>
    <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>测试自定义标签<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>请选择你热爱的运动哟 (づ￣3￣)づ╭❤～<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"choose_when_otherwise.jsp"</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span>  <span class="hljs-attr">name</span> = <span class="hljs-string">"hobby"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"badminton"</span>/&gt;</span>羽毛球
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span>  <span class="hljs-attr">name</span> = <span class="hljs-string">"hobby"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"footall"</span>/&gt;</span>足球
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span>  <span class="hljs-attr">name</span> = <span class="hljs-string">"hobby"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"basketball"</span>/&gt;</span>篮球
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span>  <span class="hljs-attr">name</span> = <span class="hljs-string">"hobby"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"others"</span>/&gt;</span>其它<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"提交"</span>/&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>

</li>
</ol>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=UTF-8"</span>
    <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%--</span> 导入自定义的标签库描述符文件 <span class="hljs-attr">--</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%@taglib</span> <span class="hljs-attr">uri</span>=<span class="hljs-string">"https://yubuntu0109.github.io"</span>  <span class="hljs-attr">prefix</span>=<span class="hljs-string">"yu"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>测试自定义标签<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"center"</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">yu:choose</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">yu:when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">"$&#123;param.hobby=='badminton' &#125;"</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>你热爱的运动是: 羽毛球<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">yu:when</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">yu:when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">"$&#123;param.hobby=='footall' &#125;"</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>你热爱的运动是: 足球<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">yu:when</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">yu:when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">"$&#123;param.hobby=='basketball' &#125;"</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>你热爱的运动是: 篮球<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">yu:when</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">yu:otherwise</span>&gt;</span>
					<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>哎哟 ~ 难道你只会coding ! ヾ(◍°∇°◍)ﾉﾞ<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
				<span class="hljs-tag">&lt;/<span class="hljs-name">yu:otherwise</span>&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">yu:choose</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>
            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/JSP/">JSP</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/04/26/VOA-Researchers-Find-Clues-that-Depression-May-Speed-Brain-Aging/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">VOA:Researchers Find Clues that Depression May Speed Brain Aging</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/04/25/VOA-5-Habits-of-Very-Successful-People/">
                        <span class="hidden-mobile">VOA:5 Habits of Very Successful People</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "JSP 自定义标签&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
